package com_8;

import java.io.*;
import java.net.ServerSocket;

public class ServerTCP {//定义服务端

    public static void main(String[] args) throws IOException {//main方法入口并抛出异常
        ServerSocket ss = new ServerSocket(10086);//创建服务端对象
        BufferedReader br = new BufferedReader(new InputStreamReader(ss.accept().getInputStream()));
        //闯进字符缓冲输入流读取客户端发送的数据

        String line;//定义读取从客户端读取数据的行数
        String s2 = br.readLine();//读取数据
        StringBuilder sb = new StringBuilder(s2);//创建String Bulider对象以便反转字符串
        StringBuilder s = sb.reverse();//反转字符串
        String s3 = s.toString();//转化为字符串对象
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ss.accept().getOutputStream()));
        //创建字符输出流对象以便给客户端反馈
        bw.write(s3);//将转化为字符对象的字符反馈给客户端
        bw.newLine();//换行
        bw.flush();//刷新
        bw.close();//关闭资源
        br.close();//关闭资源
    }
}
